﻿@model QuanLyGiaoVuUI.Models.TienDoDeTai.DeTaiViewModel

@{
    Layout = null;
}

<style>
    #suaDeTaiDialog {
        background: white !important;
    }
    .suadetai {
        width:100%;
    }
</style>

<div>
    <div>
        @if (Model.DeTai != null)
        {
        <input type="hidden" id="maDeTai" value="@Model.DeTai.MaDeTai" />
        <table style="width: 90%;margin: 0 auto;">
            <tr>
                <td>Đề tài:</td>
                <td><input type="text" class="suadetai" id="tenDeTai" value="@Model.DeTai.TenDeTai" /></td>                
            </tr>
            <tr>
                <td>GV1:</td>
                <td>@Html.DropDownList("gvHD1", new SelectList(Model.danhSachGiangVien, "ID", "HoTenGV", @Model.DeTai.GiangVien1.ID), new { @class = "styledselect_form_1" })</td>
            </tr>
            <tr>
                <td>GV2:</td>
                <td>@Html.DropDownList("gvHD2", new SelectList(Model.danhSachGiangVien, "ID", "HoTenGV", @Model.DeTai.GiangVien2.ID), new { @class = "styledselect_form_1" })</td>
            </tr>
            <tr>
                <td>SV1:</td>
                <td>@if (Model.sinhVien1 != null)
                    {
                        <input type="text" id="sv1" value="@Model.sinhVien1.MaSinhVien" />
                        <span>SVTH:</span><span id="namesv1">@Model.sinhVien1.HoTenSV</span>                    
                    }
                    else
                    {
                        <input type="text" id="sv1" value="" />
                        <span>SVTH:</span><span id="namesv1"></span>
                    }
                </td>
            </tr>
            <tr>
                <td>SV2:</td>
                <td>@if (Model.sinhVien2 != null)
                    {
                        <input type="text" id="sv2" value="@Model.sinhVien2.MaSinhVien" /> 
                        <span>SVTH:</span><span id="namesv2">@Model.sinhVien2.HoTenSV</span>
                    }
                    else
                    {
                        <input type="text" id="sv2" value="" />
                        <span>SVTH:</span><span id="namesv2"></span>
                    }                    
                </td>
            </tr>
            <tr>
                <td></td>
                <td>
                    <a href="#" id="checknameSV" style="color:red;margin:10 auto;">Kiểm tra sinh viên</a>
                </td>
            </tr>
            <tr>
                <td>Đủ ĐK bảo vệ:</td>
                <td>
                    
                    @if (Model.DeTai.KhoaLuanTotNghiep == 1)
                    { 
                         <input type="checkbox" id="isKhoaLuan" checked="checked" value="1" />
                    }
                    else
                    {
                         <input type="checkbox" id="isKhoaLuan" value="0" />
                    }
                </td>
            </tr>
            <tr>
                <td>Mô tả:</td>
                <td><textarea id="moTa" class="suadetai" cols="11" rows="5">@Model.DeTai.MoTa</textarea></td>
            </tr>
            @*<tr>
                <td>Đã duyệt:</td>               
                <td>
                     @if (Model.DeTai.DaDuyet)
                     { 
                         <input type="checkbox" id="isDaDuyet" checked="checked"  value="" />
                     }
                     else
                     {
                         <input type="checkbox" id="isDaDuyet"  value="" />
                     }
                </td>
            </tr>*@
            <tr>
                <td>Đạt yêu cầu:</td>
                <td>
                    
                    @if (Model.DeTai.DatYeuCau)
                    { 
                        <input type="checkbox" id="isDatYeuCau" checked="checked"  value="" />
                    }
                    else
                    {
                         <input type="checkbox" id="isDatYeuCau" value="" />
                    }
                </td>
            </tr>
            <tr>
                <td>Ghi chú:</td>
                <td><textarea id="ghiChu" class="suadetai" cols="11" rows="5">@Model.DeTai.GhiChu</textarea></td>
            </tr>
            <tr>
                <td>File tài liệu:</td>
                <td>
                    <input type="text" class="suadetai" id="tenTaiLieu" value="@Model.tenFileTaiLieu" readonly="true" />
                    <input type="hidden" class="suadetai" id="fileTaiLieu" value="" />
                    <input type="button" id="btnChonTaiLieu" value="Chọn tài liệu" />
                </td>
                @*<td><td>@Html.DropDownList("fileTaiLieu", new SelectList(Model.danhSachTaiLieuLuanVan, "MaTaiLieu", "TenTapTin",@Model.DeTai.FileTaiLieu), new { @class = "fileTaiLieu" })</td></td>*@
            </tr>
            <tr>
                <td></td>
                <td><input type="button" id="luuDeTai" value="Cập nhật" /></td>
            </tr>
        </table>
        }
    </div>
    <div>
        
    </div>
</div>
<div id="ChonTaiLieuDialog"></div>

<script type="text/javascript">
    var editor = CKEDITOR.replace('moTa');
    //var ghichu = CKEDITOR.replace('ghiChu');
</script>

<script>
    $(document).ready(function () {
        $('#luuDeTai').click(function () {
            var madt = $('#maDeTai').val();
            var tendt = $('#tenDeTai').val();
            var gvhd1 = $('#gvHD1').val();
            var gvhd2 = $('#gvHD2').val();
            var isKL = document.getElementById('isKhoaLuan').checked;
            var mota = editor.getData();
            //var isDD = document.getElementById('isDaDuyet').checked;
            var isDYC = document.getElementById('isDatYeuCau').checked;
            var ghichu = $('#ghiChu').val();
            var filetl = $('#fileTaiLieu').val();
            var maSV1 = $("#sv1").val();
            var maSV2 = $("#sv2").val();

            $.post("/TienDoDeTai/SuaDeTai",
                { maDeTai: madt, tenDeTai: tendt, gvHD1: gvhd1, gvHD2: gvhd2, isKhoaLuanTN: isKL, moTa: mota, isDatYeuCau: isDYC, ghiChu: ghichu, fileTaiLieu: filetl,sv1:maSV1,sv2:maSV2 },
                function (data) {                    
                    //alert(data.message);
                    //if (data.success) {
                    //    $("#suaTaiDialog").dialog("close");
                    //}
                    ThongBao(data);
            });
        });
        $("#checknameSV").click(function () {
            var maSV1 = $("#sv1").val();
            var maSV2 = $("#sv2").val();
            $.post("/TienDoDeTai/CheckNameSinhVien/", { sv1: maSV1, sv2: maSV2 }, function (data) {
                //alert(data.sv1);
                //alert(data.sv2);
                $("#namesv1").html(data.sv1);
                $("#namesv2").html(data.sv2);
            });
        });


        $("#btnChonTaiLieu").each(function () {
            $(this).bind("click", function () {
                $("#ChonTaiLieuDialog").load("/TaiLieu/ChonTaiLieuDialog").dialog({
                    autoOpen: true,
                    width: 700,
                    height: 400,
                    title: "Chọn tài liệu",
                    buttons: {
                        "Chọn": function () {
                            if (ChonTaiLieuDialog.MaTaiLieu != null) {
                                $("#fileTaiLieu").val(ChonTaiLieuDialog.MaTaiLieu);
                                $("#tenTaiLieu").val(ChonTaiLieuDialog.TenTaiLieu);
                            }
                            $("#ChonTaiLieuDialog").dialog("close");
                        }
                    }
                });
            });
        });

    });    
    function reloadPage() {
        window.location = "/TienDoDeTai/DeTai/";
    }
    function ThongBao(data) {
        if (data.success) {
            ToastManager.showSuccessToast(data.message);
            setTimeout(function () {
                reloadPage();
            }, 2000);
        }
        else {
            ToastManager.showStickyWarningToast(data.message);
        }
    }
</script>